home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / programm / gemfsc20 / gemfsc20.lzh / GNUGEM27 / VDIINP.C < prev    next >
C/C++ Source or Header  |  1993-03-24  |  8KB  |  365 lines

  1. /*
  2.  *    Vdi input funcs library interface
  3.  *
  4.  *        vsin_mode    set input mode
  5.  *        vrq_locator input locator blocking
  6.  *        vsm_locator     input locator non-blocking
  7.  *        vrq_valuator    get vauator blocking
  8.  *        vsm_valuator    sample valuator non-blocking
  9.  *        vrq_choice    request choice blocking
  10.  *        vsm_choice    request choice non-blocking
  11.  *        vrq_string    get string blocking
  12.  *        vsm_string    get string non block
  13.  *        vsc_form    set mouse form
  14.  *        vex_timv    exchange timer interrupt vector
  15.  *        v_show_c    show cursor
  16.  *        v_hide_c    show hide
  17.  *        vex_butv    exchange button vector
  18.  *        vex_motv    exchange mouse movement vector
  19.  *        vex_curv    exchange cursor change vector
  20.  *        vq_key_s    sample kbd state
  21.  *
  22.  *            ++jrb    bammi@cadence.com
  23.  *            modified: mj -- ntomczak@vm.ucs.ualberta.ca
  24.  *
  25.  * whoever at atari/dri designed this part was
  26.  * definitely *not* on over-the-counter drugs
  27.  *
  28.  */
  29. #include "common.h"
  30.  
  31. #ifdef __DEF_ALL__
  32.  
  33. #define L_vsin_mod
  34. #define L_vsm_loca        /* provides also vrq_locator */
  35. #define L_vrq_valu
  36. #define L_vsm_valu
  37. #define L_vrq_choi
  38. #define L_vsm_choi
  39. #define L_vsm_stri        /* provides also vrq_string */
  40. #define L_vsc_form
  41. #define L_vex_timv
  42. #define L_v_show_c
  43. #define L_v_hide_c
  44. #define L_vq_mouse
  45. #define L_vex_butv
  46. #define L_vex_motv
  47. #define L_vex_curv
  48. #define L_vq_key_s
  49.  
  50. #endif /* __DEF_ALL__ */
  51.  
  52.  
  53. #ifdef L_vsin_mod
  54.  
  55. /* vsin_mode    set input mode
  56.  * returns input mode
  57.  */
  58. int vsin_mode(int handle, int dev, int mode)
  59. {
  60.     _intin[0] = dev;
  61.     _intin[1] = mode;
  62.  
  63.     __vdi__(VDI_CONTRL_ENCODE(33, 0, 2, 0), handle);
  64.  
  65.     return (int)_intout[0];
  66. }
  67. #endif /* L_vsin_mod */
  68.  
  69. /* vrq_locator    input locator (blocking)
  70.  * returns void (results in args)
  71.  */
  72.  
  73.  
  74. #ifdef L_vsm_loca
  75.  
  76. __asm__(".stabs \"_vrq_locator\",5,0,0,_vsm_locator");
  77.                     /* dept of clean tricks */
  78. /* vsm_locator input locator non-blocking
  79.  * returns coded message
  80.  *    1    coordinates changed
  81.  *    2    key pressed coordinates not changed
  82.  *    3    key pressed coordinates changed
  83.  *    0    no input
  84.  */
  85. int vsm_locator(int handle, int x, int y,
  86.          int *xout, int *yout, int *term)
  87. {
  88.     _ptsin[0] = x;
  89.     _ptsin[1] = y;
  90.  
  91.     __vdi__(VDI_CONTRL_ENCODE(28, 1, 0, 0), handle);
  92.  
  93.     *xout = _ptsout[0];
  94.     *yout = _ptsout[1];
  95.     *term = _intout[0];
  96.  
  97.     /* ignore return value for vrq_locator */
  98.     return (int)((_contrl[4] << 1) | _contrl[2]);
  99. }
  100. #endif /* L_vsm_loca */
  101.  
  102. #ifdef L_vrq_valu
  103.  
  104. /* vrq_valuator get valuator blocking
  105.  * returns void (results in args)
  106.  */
  107. void vrq_valuator(int handle, int in,
  108.           int *out,   int *term)
  109. {
  110.     _intin[0] = in;
  111.  
  112.     __vdi__(VDI_CONTRL_ENCODE(29, 0, 1, 0), handle);
  113.  
  114.     *out = _intout[0];
  115.     *term = _intout[1];
  116. }
  117. #endif /* L_vrq_valu */
  118.  
  119. #ifdef L_vsm_valu
  120.  
  121. /* vsm_valuator sample valuator (non-block)
  122.  * returns void (results in args)
  123.  */
  124. void vsm_valuator(int handle, int in,
  125.           int *out,   int *term, int *status)
  126. {
  127.     _intin[0] = in;
  128.  
  129.     __vdi__(VDI_CONTRL_ENCODE(29, 0, 1, 0), handle);
  130.  
  131.     *out = _intout[0];
  132.     *term = _intout[1];
  133.     *status = _contrl[4];
  134. }
  135. #endif /* L_vsm_valu */
  136.  
  137. #ifdef L_vrq_choi
  138.  
  139. /* vrq_choice    request choice blocking
  140.  * returns void (result in arg)
  141.  */
  142. void vrq_choice(int handle, int cin, int *cout)
  143. {
  144.     _intin[0] = cin;
  145.  
  146.     __vdi__(VDI_CONTRL_ENCODE(30, 0, 1, 0), handle);
  147.  
  148.     *cout = _intout[0];
  149. }
  150. #endif /* L_vrq_choi */
  151.  
  152. #ifdef L_vsm_choi
  153.  
  154. /* vsm_choice    request choice (non-block)
  155.  * returns status and choice in arg
  156.  */
  157. int vsm_choice(int handle, int *choice)
  158. {
  159.     __vdi__(VDI_CONTRL_ENCODE(30, 0, 0, 0), handle);
  160.  
  161.     *choice = _intout[0];
  162.     return (int)_contrl[4];
  163. }
  164. #endif /* L_vsm_choi */
  165.  
  166. #ifdef L_vsm_stri
  167.  
  168. /* vrq_string    get string blocking
  169.  * returns void (string in arg)
  170.  * void vrq_string(int handle, int len, int echo, int echoxy[], char *str)
  171.  */
  172. __asm__(".stabs \"_vrq_string\",5,0,0,_vsm_string"); /* dept of clean tricks */
  173. /* vsm_string    get string non block
  174.  * returns 0 no chars avail >0 chars avail
  175.  *
  176.  * The code below does not use VDI_CONTRL_ENCODE macro since
  177.  * len can be a negative number.
  178.  */
  179. /*
  180.  * Both functions will handle strings up to INTINMAX characters in
  181.  * length (currently 255). Note that if length is specified as
  182.  * a negative number then scan codes are available after a call
  183.  * in _intin[] array  (not _intout! - this binding temporarily
  184.  * switches roles of _intin and _intout).
  185.  */
  186.  
  187.  
  188. int vsm_string(int handle, int len, int echo, int echoxy[], char *str)
  189. {
  190.     short status;
  191.     short *end, *wptr = _intout;
  192.  
  193.     /* Switch roles of _intin and _intout */
  194.     _vdiparams[1] = (void *)wptr;
  195.     _vdiparams[3] = (void *)&_intin[0];
  196.  
  197.     *wptr++ = len;
  198.     *wptr++ = echo;
  199.  
  200.      wptr = (short *)_contrl;
  201.     *wptr++  = 31;    /* 0  - opcode */
  202.     *wptr++  = 1;    /* 1 */
  203.      wptr++;        /* 2 */
  204.     *wptr     = 2;    /* 3  - # of entries in _intout (this time) */
  205.      wptr[3] = handle;    /* 6 - handle */
  206.     vdi();        /* call vdi */
  207.  
  208.     status = _contrl[4];
  209.     wptr = _intin;
  210.     end = wptr + status;
  211.     while (wptr < end)
  212.     *str++ = *wptr++;
  213.     *str = '\0';
  214.  
  215.     /* Restore usual meaning of _intin and _intout */
  216.     _vdiparams[1] = (void *)&_intin[0];
  217.     _vdiparams[3] = (void *)&_intout[0];
  218.  
  219.     return (int) status; /* not used by vrq_string */
  220. }
  221. #endif /* L_vsm_stri */
  222.  
  223.  
  224. #ifdef L_vsc_form
  225.  
  226. /* vsc_form set mouse form
  227.  * returns void
  228.  */
  229. void vsc_form(int handle, int form[])
  230. {
  231.  
  232. #ifdef __MSHORT__
  233.     _vdiparams[1] = &form[0];
  234. #else
  235.     int   *end = form + 37;
  236.     short *wptr = _intin;
  237.  
  238.     do {
  239.     *wptr++ = *form++;
  240.     } while (form < end);
  241. #endif
  242.  
  243.     __vdi__(VDI_CONTRL_ENCODE(111, 0, 37, 0), handle);
  244. #ifdef __MSHORT__
  245.     _vdiparams[1] = (void *)&_intin[0];
  246. #endif
  247. }
  248. #endif /* L_vsc_form */
  249.  
  250. #ifdef L_vex_timv
  251.  
  252. /* vex_timv exchange timer interrupt vector
  253.  * returns void (results in args)
  254.  */
  255. void vex_timv(int handle, void *time_addr,
  256.           void **otime_addr, int *time_conv)
  257. {
  258.     *((void **)(&_contrl[7])) = time_addr;
  259.  
  260.     __vdi__(VDI_CONTRL_ENCODE(118, 0, 0, 0), handle);
  261.  
  262.     *otime_addr = *((void **)(&_contrl[9]));
  263.     *time_conv    = _intout[0];
  264. }
  265. #endif /* L_vex_timv */
  266.  
  267. #ifdef L_v_show_c
  268.  
  269. /* v_show_c show cursor
  270.  * returns void
  271.  */
  272. void v_show_c(int handle, int reset)
  273. {
  274.     _intin[0] = reset;
  275.  
  276.     __vdi__(VDI_CONTRL_ENCODE(122, 0, 1, 0), handle);
  277. }
  278. #endif /* L_v_show_c */
  279.  
  280. #ifdef L_v_hide_c
  281.  
  282. /* v_hide_c show hide
  283.  * returns void
  284.  */
  285. void v_hide_c(int handle)
  286. {
  287.     __vdi__(VDI_CONTRL_ENCODE(123, 0, 0, 0), handle);
  288. }
  289. #endif /* L_v_hide_c */
  290.  
  291. #ifdef L_vq_mouse
  292.  
  293. /* vq_mouse sample mouse button state
  294.  * returns void (results in args
  295.  */
  296. void vq_mouse(int handle, int *pstatus, int *x, int *y)
  297. {
  298.     __vdi__(VDI_CONTRL_ENCODE(124, 0, 0, 0), handle);
  299.  
  300.     *pstatus = _intout[0];
  301.     *x = _ptsout[0];
  302.     *y = _ptsout[1];
  303. }
  304. #endif /* L_vq_mouse */
  305.  
  306. #ifdef L_vex_butv
  307.  
  308. /* vex_butv exchange button vector
  309.  * returns void (results in args)
  310.  */
  311. void vex_butv(int handle, void *new, void **old)
  312. {
  313.     *((void **)(&_contrl[7])) = new;
  314.  
  315.     __vdi__(VDI_CONTRL_ENCODE(125, 0, 0, 0), handle);
  316.  
  317.     *old = *((void **)(&_contrl[9]));
  318. }
  319. #endif /* L_vex_butv */
  320.  
  321. #ifdef L_vex_motv
  322.  
  323. /* vex_motv exchange mouse movement vector
  324.  * returns void (result in arg)
  325.  */
  326. void vex_motv(int handle, void *new, void **old)
  327. {
  328.     *((void **)(&_contrl[7])) = new;
  329.  
  330.     __vdi__(VDI_CONTRL_ENCODE(126, 0, 0, 0), handle);
  331.  
  332.     *old = *((void **)(&_contrl[9]));
  333. }
  334. #endif /* L_vex_motv */
  335.  
  336. #ifdef L_vex_curv
  337.  
  338. /* vex_curv exchange cursor change vector
  339.  * returns void (result in arg)
  340.  */
  341. void vex_curv(int handle, void *new, void **old)
  342. {
  343.     *((void **)(&_contrl[7])) = new;
  344.  
  345.     __vdi__(VDI_CONTRL_ENCODE(127, 0, 0, 0), handle);
  346.  
  347.     *old = *((void **)(&_contrl[9]));
  348. }
  349. #endif /* L_vex_curv */
  350.  
  351. #ifdef L_vq_key_s
  352.  
  353. /* vq_key_s sample kbd state
  354.  * returns void (result in arg)
  355.  */
  356. void vq_key_s(int handle, int *state)
  357. {
  358.     __vdi__(VDI_CONTRL_ENCODE(128, 0, 0, 0), handle);
  359.  
  360.     *state = _intout[0];
  361. }
  362. #endif /* L_vq_key_s */
  363.  
  364. /* -eof- */
  365.